<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>联币ICO</title>
	<meta name="csrf-token" content="{{ csrf_token() }}">
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<link rel="stylesheet" type="text/css" href="__ROOT__/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="__ROOT__/css/bootstrap-theme.css">
	<link rel="stylesheet" type="text/css" href="__ROOT__/css/common.css">
	<style type="text/css">
        input[type='number'] {
            -moz-appearance:textfield;
        }
        input[type=number]::-webkit-inner-spin-button,
        input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
        }
    </style>
</head>
<body>
	<div class="wrap wrap-reg container-fluid" >
		<form action="/index.php?s=index/index/findPassword" class="reg-form" method="post" accept-charset="utf-8">
			 <div class="form-group">
			 	<h1>密码修改</h1>
				</div>
			 <div class="form-group">
			    <input type="text" name="mobile" class="form-control" id="mobile"  oninput="check_phone();" placeholder="请输入手机号码">
			  </div>
			  <div class="form-group valume">
			    <input type="text" name="code" class="form-control"  oninput="check_code(this);" id="code" placeholder="请输入验证码">
			     <button type="button"  class="btn btn-success" id='getcode' disabled value="1">获取验证码</button>
			  </div>
			  <div class="form-group">
			    <input type="password" name="password" id="password" class="form-control"  oninput="if(value.length>16){value=value.slice(0,16);layer.msg('密码最长为16')};" placeholder="请设置登录密码">
			  </div>
			  <div class="form-group">
			    <input type="password" name="re_password"  id="re_password" class="form-control"  oninput="if(value.length>16){value=value.slice(0,16);layer.msg('密码最长为16')};" placeholder="请确认登录密码">
			  </div>
				<input type="hidden" name="msg_id" value="">
			  <div class="form-group">
			  	<button type="submit" class="btn btn-success">提交</button>
			  </div>
			   <div class="form-group alink">
			  		<a href="register.html" title="" class="pull-right">没有账号,立即注册!</a>
			  </div>
		</form>
    	<input type="hidden" name="" class="error" value="{$error ?: ''}">
	</div>
	<script type="text/javascript" src='__ROOT__/js/jquery.js'></script>
	<script type="text/javascript" src='__ROOT__/assets/jquery.js'></script>
	<script type="text/javascript" src='__ROOT__/layer/layer.js'></script>
	<script type="text/javascript" src='__ROOT__/js/getCode.js'></script>
	<script type="text/javascript" >
	//限制手机输入框格式及检查是否被注册
    function check_phone(){
        var mobile = $('#mobile').val();
        var reg = /\d+/;
        //禁止符号（. +）;
        if(!reg.test(mobile)){
            $('#mobile').val('');
            // layer.msg('请输入正确的手机格式！',{icon:2,time:1000});
        }
        if(mobile.length>=12){
            $('#mobile').val(mobile.slice(0,11));
            var mobile_last = $('#mobile').val();
        }
        if(mobile.length==11){
            //匹配手机号格式
            var phone_reg = /^1[3578]\d{9}$/;
            if(!phone_reg.test(mobile)){
                layer.msg('请输入正确的手机格式！',{icon:2,time:1000});
                return false;
            }
            $.post("{:url('index/index/check_is_register')}",{username:$('#mobile').val()},function(e){
                if(e.code==1){
                	$('#getcode').removeAttr('disabled');
                }else{
                	layer.msg('该账号不存在！',{icon:2,time:2000});
                	$('#getcode').attr("disabled",'disabled');
                }
            })
        }
    }

    //验证码验证
    function check_code(index){
        var code = $(index).val();
        var reg = /\d+/;
        if(!reg.test(code)){
            layer.msg('请输入正确格式的验证码!');
            $(index).val('');
        }else if(code.length>6){
            $(index).val(code.slice(0,6));
        }
    }

	$(function(){
		Code.getcode($, '#getcode', '/index.php?s=index/index/sendPhoneCode', function (msg) {
			$('input[name="msg_id"]').val(msg.msg_id)
			Code.timeStart($, 60, '#getcode', Code.isClicked)
		});
		 $('form').submit(function(){
            // if(!$('input[type="text"]').val()){
            //     layer.msg($(this).attr('placeholder'));
            //     return false;
            // }
            if($('#mobile').val()==''){
                layer.msg($('#mobile').attr('placeholder'));
                return false;
            }
            if($('#code').val()==''){
                layer.msg($('#code').attr('placeholder'));
                return false;
            }
            if($('#password').val()==''){
                layer.msg($('#password').attr('placeholder'));
                return false;
            }
            if($('#re_password').val()==''){
                layer.msg($('#re_password').attr('placeholder'));
                return false;
            }
            var password = $('input[name="password"]');
            var re_password = $('input[name="re_password"]');
            if(password.length != 0 && password.val() != re_password.val()){
                layer.msg('两次密码不一致！')
                return false
            }
            if(password.val().length<6||re_password.val().length<6){
                layer.msg('密码最短需要6位！');
                return false
            }
            $.post("{:url('findPassword')}",$('form').serialize(),function(e){
            	if(e.code==1){
                    layer.msg(e.msg,{icon:1,time:2000});
                    setTimeout("window.location.href='"+e.url+"'",2000);
                }else{
                    layer.msg(e.msg,{icon:2,time:2000});
                }
            })
            return false
        })
		if ($('.error').val()) {
            layer.alert($('.error').val(), {icon: 5})
        }
	})
		
	</script>
</body>
</html>